var express = require('express');
var router = express.Router();
var jwt = require('jsonwebtoken'); // 使用jwt签名
/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with a resource');
});
// 用户授权路径，返回JWT 的 Token 验证用户名密码
router.post('/auth', function (req, res) {
  console.log(req.body);
  var user = { password: "123", name: "admin" }
  if (user.name != req.body.name) {
    res.json({ success: false, message: '未找到授权用户' });
  } else if (user) {
    if (user.password != req.body.password) {
      res.json({ success: false, message: '用户密码错误' });
    } else {
      var token = jwt.sign(user, "shengzhijie", {
        expiresIn: 6// 授权时效24小时
      });
      res.json({
        success: true,
        message: '请使用您的授权码',
        token: token
      });
    }
  }
});
module.exports = router;
